package com.lch.base.http;

import android.content.Context;
import android.support.annotation.NonNull;

import com.lch.base.http.callback.ICallbackBase;
import com.lch.base.http.config.CacheProvide;
import com.lch.base.http.model.params.BaseParam;
import com.trello.rxlifecycle2.LifecycleProvider;

/**
 * 请求设置包装类，可自定义
 *
 * @author lee(29487113@qq.com) on 18/2/4
 */
public class HttpUtils {
    /**
     * 初始化基本参数， 项目初始化时调用
     * @param context
     * @param baseUrl
     * @return
     */
    public static HttpConfig.Builder builderConfig(Context context, @NonNull String baseUrl, boolean isShowLog) {
        return new HttpConfig.Builder(context, baseUrl, isShowLog, false, CacheProvide.CACHE_TYPE.CACHE_CLIENT);
    }

    public static HttpBuilder request() {
        return new HttpBuilder();
    }
    public static HttpBuilder request(@NonNull String url, BaseParam baseParam) {
        return new HttpBuilder(url, baseParam);
    }

    public static void get(Context context, @NonNull String url, BaseParam baseParam, LifecycleProvider lifecycleProvider, ICallbackBase callback) {
        new HttpBuilder(url, baseParam)
                .bindToLifecycle(lifecycleProvider) //绑定生命周期
                .setShowLoad(true, context)
                .setCallback(callback)
                .get();
    }



//    public static void get(String url, Map<String, String> params, APICallback callback) {
//        new HttpBuilder(url, params)
//                .success(str -> {
//                    if (callback != null) {
//                        callback.onSuccess(str);
//                    }
//                })
//                .error(v -> {
//                    if (callback != null) {
//                        callback.onFailed();
//                    }
//                })
//                .get();
//    }

}
